
let l = [("Don", 435.);("Nut", 75.);("Toto", 42.)];;

let compare a x = if a < x then -1
  else if x = a then 0 
  else 1;;

let rec find c l = match (c,l) with 
    (cl, []) -> failwith "Le client n'a pas ete trouve"
  | (cl, (n, c)::l) -> if  (String.lowercase cl) = (String.lowercase n) then
                               c
                       else find cl l;;

find "nut" l;;

let rec add cl liste = match (cl, liste) with 
    (_, []) -> cl::l
  | ((a1, b1), (a2,b2)::l) -> match compare (String.lowercase a2) (String.lowercase a1) with 
	                           
                                  | 0 -> liste
				  | (-1) -> (a2,b2)::(add cl l)
                                  | _ -> cl::(a2,b2)::l;;
      

add ("Tonio", 4532.) l;;

let rec delete cl = function
   [] -> []
  |((a,x)::l) -> if a = cl then l
    else (a,x)::(delete cl l);;


delete "Tonio" l;;

let rec update nom x l = match l with
      [] -> (nom,x)::[]
    | (a,b)::l -> if a = nom then
	(a,x)::l
      else
	(a,b)::(update nom x l);;

update "Toto" 45. l;;


let name anom nnom l = add (nnom, find anom l) (delete anom l);;

name "Nut" "Acdc" l;;


let rec map f = function
   [] -> [] 
  |e::l -> f e:: map f l;;


let sales l x = map (function (a,b) -> (a, b-.((b/.100.)*.x))) l;;

sales l 10.;;



let l2 = [("Don", 543.56);("Fillipo",674.23);("Tototo",12.12)];;

let rec fusion = function
    (l, []) | ([],l) -> l
  | ((a1,b1)::l1, (a2,b2)::l2) -> match (compare (String.lowercase a1) (String.lowercase a2)) with
	                   (-1) -> (a1,b1)::(fusion (l1, ((a2,b2)::l2)))
			 | 0 -> (a1,b1+.b2)::(fusion (l1, l2))
		         | _ -> (a2,b2)::(fusion (((a1,b1)::l1), l2));;

fusion (l,l2);;
